package com.maiji.cloud.controller;

import com.maiji.cloud.config.MyRedisConfig;
import com.maiji.cloud.entities.login.AppUser;
import com.maiji.cloud.microservice.UserInfoService;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.utils.RedisUtil;
import org.eclipse.jetty.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

public class BaseContronller {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private UserInfoService userInfoService;

    public String getUserId (String token) {
        if (StringUtil.isBlank(token)) return null;
        AppUser appUser = RedisUtil.getAppUserByRedis(redisTemplate, MyRedisConfig.REDISDATABASENO, token, userInfoService);
        if (appUser == null) {
            BaseDataResDto<AppUser> baseDataResDto = userInfoService.checkToken(token, false);
            appUser = baseDataResDto.getData();
        }
        return appUser.getUuId();
    }

}
